package com.yunyike.wx.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期工具类
 * 
 * @author wenjian
 *
 */
public final class DateUtil {

	/**
	 * yyyy-MM-dd HH:mm:ss
	 */
	public static final SimpleDateFormat DATE_TIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	/**
	 * 将日期以2007-01-30 08:30:59的格式输出
	 */
	public static String formatDateTime(Date date) {
		if (date == null) {
			return "";
		}
		return DATE_TIME_FORMATTER.format(date);
	}

	/**
	 * 解析2007-01-30 08:30:59的格式的日期
	 */
	public static Date parseDateTime(String dateTime) {
		try {
			return DATE_TIME_FORMATTER.parse(dateTime);
		} catch (ParseException ex) {
			throw new RuntimeException("Date parse error: " + dateTime + " , expected format is "
					+ DATE_TIME_FORMATTER.toPattern(), ex);
		}
	}
}
